import request from '@/utils/request'

export interface CategoryInfo {
  categoryId: number
  categoryName: string
  description: string
  parentId: number | null
  children: CategoryInfo[]
  createdAt: string
  updatedAt: string
}

export interface CategoryListParams {
  page: number
  pageSize: number
  categoryName?: string
}

export interface CategoryListResponse {
  list: CategoryInfo[]
  total: number
  page: number
  pageSize: number
}

export interface CreateCategoryParams {
  categoryName: string
  description: string
  parentId: number | null
}

export interface CreateCategoryResponse {
  categoryId: number
  categoryName: string
  description: string
  parentId: number | null
  createdAt: string
  updatedAt: string
}

export interface CategoryDetailResponse {
  categoryId: number
  categoryName: string
  description: string
  parentId: number | null
  children: CategoryInfo[]
  createdAt: string
  updatedAt: string
}

const categoryApi = {
  // 获取分类列表
  getCategoryList(params: CategoryListParams) {
    return request.get<CategoryListResponse>('/getCategories', { params })
  },
  // 创建分类
  createCategory(data: CreateCategoryParams) {
    return request.post<CreateCategoryResponse>('/createCategory', data)
  },
  // 删除分类
  deleteCategory(categoryId: number) {
    return request.delete(`/deleteCategory/${categoryId}`)
  },
  // 获取单个分类详情
  getCategoryById(id: number) {
    return request.get<CategoryDetailResponse>(`/categoriesById/${id}`)
  }
}

export default categoryApi